<template>
  <div class="header-info">
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">区域设置</el-divider>
      </div>
      <el-form-item label="区域高度">
        <el-input-number
            :min="100"
            size="small"
            v-model="optionsInfo.areaHeight"
        />
      </el-form-item>
      <el-form-item label="顶部外边距">
        <el-input-number
            size="small"
            v-model="optionsInfo.marginTop"
        />
      </el-form-item>
    </div>

    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">队列标题设置</el-divider>
      </div>
      <template v-for="item in optionsInfo['headerInfo']['content']">
        <el-form-item :label="item.label" class="replenish-shown">
          <el-input v-model="item.value" placeholder="请输入内容" size="small"/>
        </el-form-item>
      </template>

      <el-form-item label="字号" class="replenish-shown">
        <el-input-number
            :min="12"
            size="small"
            v-model="optionsInfo['headerInfo']['fontSize']"
        />
      </el-form-item>
      <el-form-item label="字体颜色" class="replenish-shown">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['headerInfo']['color']"
        />
      </el-form-item>
      <el-form-item label="字体粗细" class="replenish-shown">
        <el-select v-model="optionsInfo['headerInfo']['fontWeight']" placeholder="请选择">
          <el-option
              v-for="item in fontWeightOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="背景颜色" class="replenish-shown">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['headerInfo']['background']"
        />
      </el-form-item>
    </div>
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">队列患者设置</el-divider>
      </div>
      <el-form-item label="字号" class="replenish-shown">
        <el-input-number
            :min="12"
            size="small"
            v-model="optionsInfo['listInfo']['fontSize']"
        />
      </el-form-item>
      <el-form-item label="字体颜色" class="replenish-shown">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['listInfo']['color']"
        />
      </el-form-item>
      <el-form-item label="字体粗细" class="replenish-shown">
        <el-select v-model="optionsInfo['listInfo']['fontWeight']" placeholder="请选择">
          <el-option
              v-for="item in fontWeightOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="背景颜色" class="replenish-shown">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['listInfo']['background']"
        />
      </el-form-item>

      <el-form-item label="是否滚动" class="replenish-shown">
        <el-switch v-model="optionsInfo['scroll']"/>
      </el-form-item>
      <el-form-item label="首屏列数" class="replenish-shown" v-if="false">
        <el-input-number
            :min="4"
            :max="6"
            size="small"
            v-model="optionsInfo.viewNumber"
        />
      </el-form-item>
      <el-form-item label="开始滚动列数" class="replenish-shown">
        <el-input-number
            :min="1"
            size="small"
            v-model="optionsInfo.scrollNumber"
        />
      </el-form-item>
      <el-form-item label="滚动速度" class="replenish-shown">
        <el-input-number
            :min="1"
            :max="4"
            size="small"
            v-model="optionsInfo.scrollStep"
        />
      </el-form-item>
    </div>


    <template v-if="true">
      <div class="list-item-setting">
        <div class="title-info">
          <el-divider content-position="left">切屏间隔</el-divider>
        </div>
        <el-form-item label="切屏状态">
          <el-switch v-model="optionsInfo['switchState']" :disabled="optionsInfo['switchDisabled'] "/>
        </el-form-item>

        <el-form-item label="切屏间隔">
          <el-input-number
              :min="1"
              size="small"
              :disabled="!optionsInfo['switchState']"
              v-model="optionsInfo['switchTime']"
          />
        </el-form-item>
      </div>

      <div class="list-item-setting">
        <div class="title-info">
          <el-divider content-position="left">接口设置</el-divider>
        </div>
        <el-form-item label="接口状态" class="replenish-shown">
          <el-switch v-model="optionsInfo['ApiState']"/>
        </el-form-item>
        <template v-if="optionsInfo['ApiState']">

          <!--接口类型-->
          <el-form-item label="接口类型">
            <el-select
                size="small"
                placeholder="请选择"
                v-model="optionsInfo['ApiType']"
                :disabled="!!(optionsInfo?.publishType)"
            >
              <el-option
                  v-for="item in ApiTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>

          <!--接口地址-->
          <el-form-item
              label="接口地址"
              v-if="optionsInfo['ApiType']===1"
          >
            <el-input
                size="small"
                placeholder="请输入内容"
                v-model="optionsInfo['ApiAddress']"
            />
          </el-form-item>

          <!--接口标识-->
          <el-form-item
              label="接口标识"
              v-if="optionsInfo['ApiType']===2"
          >
            <el-input
                v-model="optionsInfo['ApiSign']"
                size="small"
                placeholder="请输入内容"
            />
          </el-form-item>

          <!--接口请求频次-->
          <el-form-item label="请求频次(s)">
            <el-input-number
                size="small"
                v-model="optionsInfo['frequencyApi']"
            />
          </el-form-item>

        </template>
      </div>
    </template>

  </div>
</template>

<script>
import Draggable from "vuedraggable";
import constantDic from "@/utils/vue-i18n/lang/zh-CN";
import * as types from "@c/public/form-designer/devType/datas-types";

export default {
  name: "publishDrugstore-editor",

  componentName: "publishDrugstore-editor",

  mixins: [],

  components: {Draggable},

  props: {
    designer: Object,
    optionModel: Object,
    selectedWidget: Object,
  },

  inject: ['serverFieldList', 'getDesignerConfig'],

  data() {
    return {
      radio: 1,
      screenType: '',
      optionsInfo: Object(),
      constantDic: constantDic,
      ApiTypeOptions: [
        {
          value: 1,
          label: '接口地址'
        },
        {
          value: 2,
          label: '接口标识'
        }
      ],
      predefineColors: types['predefineColors'],
      fontWeightOptions: types['fontWeightOptions']
    }
  },

  computed: {
    fieldHas() {
      return function (field) {
        return Reflect.has(this.optionsInfo, field)
      }
    },

    switchTimeShow() {
      let {isMainScreen, switchState} = this.optionsInfo;
      if (!(Reflect.has(this.optionsInfo, 'isMainScreen'))) {
        return switchState;
      } else {
        return isMainScreen;
      }
    },

  },

  methods: {
    handleDragEnd(val) {
      console.log(val)
    },

    handlePatientListTotal(val) {
      let {patientListRow, patientListCol} = this.optionsInfo;
      Reflect.set((this.optionsInfo), 'patientListTotal', (patientListRow * patientListCol));
    }
  },

  watch: {
    optionModel: {
      handler: function (val) {
        let key = (val.config)
        this.optionsInfo = val[key];
      },
      deep: true,
      immediate: true
    }
  }
}
</script>


<style lang="scss" scoped>
.col-info {

  ::v-deep .el-form-item__content {
    margin-left: 1px !important;

    .title {
      width: 100%;
    }

    .el-checkbox__label {
      width: auto;
    }


    .el-icon-thumb {
      position: relative;
      top: 8px;
      padding-left: 10px;
      font-size: 18px;
      text-align: center;
    }

    .el-checkbox {
      width: calc(100% - 32px);
    }
  }

}

.row-option {
  :deep(.el-checkbox) {
    display: flex;
    flex-direction: row;

    .el-checkbox__input {
      display: flex;
      align-self: flex-start;
      align-items: flex-start;
    }

    .el-checkbox__label {
      display: flex;
      flex-direction: row;

      .setting-info {
        display: flex;
        flex-direction: column;

        .el-input {
          width: 100%;
          margin-bottom: 20px;

          input[type="number"] {
            line-height: normal !important;
          }
        }

        .el-input-number {
          width: 100%;
        }

        .el-input__inner {
          padding-right: 0 !important;
        }
      }
    }
  }


}
</style>